//
//  NavView.m
//  UHealth
//
//  Created by hanyou on 15/3/18.
//  Copyright (c) 2015年 gjtx. All rights reserved.
//

#import "NavView.h"

@interface NavView ()

@property (nonatomic,strong) UIViewController *svc;
/**   */
@property (nonatomic, weak) UILabel *midLabel;
@end


@implementation NavView

-(id)initWithFrame:(CGRect)frame andTitleStr:(NSString *)title{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kBlueColor;
        UILabel *midLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 27, frame.size.width -200, 30)];
        midLabel.font = [UIFont systemFontOfSize:17];
        midLabel.textColor = [UIColor whiteColor];
        midLabel.text = title;
        midLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:midLabel];
        self.midLabel = midLabel;
    }
    return self;
}

-(id)initWithFrame:(CGRect)frame andTitleStr:(NSString *)title andVC:(UIViewController *)vc{
    self = [super initWithFrame:frame];
    if (self) {
        _svc = vc;
        self.backgroundColor = kBlueColor;
        UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 10, 64, 64)];
        [backBtn setImage:[UIImage imageNamed:@"arrow_left_top_back"] forState:UIControlStateNormal];
        [backBtn addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *midLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 27, frame.size.width -200, 30)];
        midLabel.font = [UIFont systemFontOfSize:17];
        midLabel.textColor = [UIColor whiteColor];
        midLabel.text = title;
        midLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:backBtn];
        [self addSubview:midLabel];
        self.midLabel = midLabel;
    }
    return self;
    
}

- (void)BtnClick:(UIButton *)btn
{
    if (self.block) {
        self.block();
    }
    [_svc dismissViewControllerAnimated:YES completion:^{}];
}


- (void)setTitleName:(NSString *)titleName {
    _titleName = titleName;
    
    self.midLabel.text = _titleName;
}

@end
